import type { QmsDefect } from "@/pages/qms/defect/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
  //缺陷编码
  defectCode?: string;
  //缺陷描述
  defectName?: string;
  //检测项类型
  indexId?: string;
  //缺陷等级
  defectLevel?: string;
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: QmsDefect[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/qms/defect/pageList",
    data
});
const getInfo = (id: React.Key): Promise<QmsDefect> =>
  apiClient.get({
    url: `/qms/defect/${id}`
});

const add = (data: QmsDefect): Promise<QmsDefect> =>
  apiClient.post({
    url: "/qms/defect",
    data
});

const update = (data: QmsDefect): Promise<QmsDefect> =>
  apiClient.put({
    url: "/qms/defect",
    data
});

const remove = (ids: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/qms/defect",
    params: {
    ids: ids.join(",")
  }
});
export const qmsDefectService = {
  pageList,
  getInfo,
  add,
  update,
  remove,
};

export default qmsDefectService;